package edu.whu.rose.clock.kps.algorithm.blinks.search2;

import com.sleepycat.je.DatabaseException;

import edu.whu.rose.clock.kps.algorithm.blinks.index.BilevelIndexDB;
import edu.whu.rose.clock.kps.algorithm.blinks.index.PNEntry;
import edu.whu.rose.clock.kps.datastruct.SimpleSubgraphVertex;

public class PNCursor2 extends Cursor2 {

	private final double base;
	
	public PNCursor2(int block, BilevelIndexDB bidb, int portal, double base) {
		super(block, bidb);
		this.base = base;
		SimpleSubgraphVertex bk = new SimpleSubgraphVertex(block, portal);
		try {
			list = bidb.getFromPortalVertex(bk);
			if (list == null) {
				System.err.println("Error: cannot find PN list for block #" + block + " and portal #" + portal);
				System.exit(1);
			}
		}
		catch (DatabaseException ex) {
			ex.printStackTrace();
		}
	}

	public int getFirst() {
		return ((PNEntry)list[pos]).getFirst();
	}

	public int getNode() {
		return ((PNEntry)list[pos]).getNode();
	}

	public double getDistance() {
		return base + ((PNEntry)list[pos]).getDistance();
	}

	public double peek() {
		return base + ((PNEntry)list[pos + 1]).getDistance();
	}

}
